import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';
import 'package:xm_app/common/logger/LoggerUtil.dart';

import 'custom_video_panel.dart';

class VideoWidget extends StatefulWidget {
  @override
  _VideoWidgetState createState() => _VideoWidgetState();
}

class _VideoWidgetState extends State<VideoWidget> {
  FijkPlayer _fijkPlayer;
  @override
  void initState() {
    super.initState();
    _fijkPlayer = FijkPlayer();
    //设置视频资源
    _fijkPlayer.setDataSource("https://douban.donghongzuida.com/20201210/13776_5a55fb63/index.m3u8", autoPlay: true, showCover: true);
  }

  @override
  Widget build(BuildContext context) {
    return AspectRatio(
      aspectRatio: 16 / 9,
      child: Stack(
        children: <Widget>[
          _fijkPlayer == null
              ? Container(
                  color: Colors.black,
                )
              : FijkView(
                  player: _fijkPlayer,
                  fit: FijkFit.ar16_9,
                  fsFit: FijkFit.ar16_9,
                  color: Colors.black,
                  panelBuilder: fijkCustomerPanelBuilder(
                      snapShot: true,
                      title: "test",
                      onBack: () {
                        logInfo("onBack");
                      }),
                  onDispose: (fijkData) {
                    //进行数据的保存
                    logInfo("onDispose");
                  },
                ),
        ],
      ),
    );
  }
}
